<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" SRC="./resource/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript">
    KindEditor.ready(function(K){
        K.create('textarea[name="content"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
    });
</script>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['service_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <form id="add_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <input type="hidden" id="service_id" name="service_id" value="<?php echo $output['serviceInfo']['service_id'] ?>" />
        <table class="table tb-type2 nobdb">
            <tbody>
            <tr class="noborder">
                <td colspan="2" class="required"><label class="validation" for="service_title"><?php echo $lang['service_index_title'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="service_title" name="service_title" class="txt" value="<?php echo $output['serviceInfo']['service_title'] ?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation" for="service_sort"><?php echo $lang['nc_common_sort'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="service_sort" name="service_sort" class="txt" value="<?php echo $output['serviceInfo']['service_sort'] ?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td colspan="2"><label class="validation" for=""><?php echo $lang['service_add_introduction'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform" colspan="2"><textarea rows="3" cols="20" id="service_introduction" name="service_introduction" class="txt"><?php echo $output['serviceInfo']['service_introduction'] ?></textarea></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation" for="content"><?php echo $lang['service_add_content']?></label></td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform"><textarea id="content" name="content" class="txt" style="width:70%;height: 480px;"><?php echo $output['serviceInfo']['service_content'] ?></textarea></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script>
    //按钮先执行验证再提交表
    $(document).ready(function(){
        //按钮先执行验证再提交表单
        $("#submitBtn").click(function(){
            if($("#add_form").valid()){
                $("#add_form").submit();
            }
        });

        $("#add_form").validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parent().parent().prev().find('td:first'));
            },
            rules : {
                service_title :{ required : true},
                service_sort :{ required : true, digits:true},
                content:{ required : true}
            },
            messages : {
                service_title : {
                    required : '<?php echo $lang['service_add_title_null'];?>',
                },
                service_sort : {
                    required : '<?php echo $lang['service_add_sort_null']?>',
                    digits: '<?php echo $lang['service_add_sort_int']?>'
                },
                content:{
                    required : '<?php echo $lang['service_add_content_null'];?>',
                }
            }
        });
    });
</script>
